Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix memory corruption in gluoncv ssd training #13727

Merged
merged 1 commit into from
Jan 8, 2019

Conversation

arcadiaphy
Copy link
Member

Description

Fix #13710

In bipartite match, the temporary workspace size is miscalculated and not enough to hold the index tensor.

Since it is related to sizeof(DType) and sizeof(int32_t), the bug is only triggered on some platforms.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@zhreshold
Copy link
Member

LGTM, thanks @arcadiaphy

@@ -785,7 +785,7 @@ void BipartiteMatchingForward(const nnvm::NodeAttrs& attrs,
.get_with_shape<xpu, 2, DType>(Shape2(batch_size, col), s);
Shape<1> sort_index_shape = Shape1(dshape.Size());
index_t workspace_size = sort_index_shape.Size();
workspace_size += ((sort_index_shape.Size() * sizeof(int32_t) - 1) / sizeof(DType)) * 2;
workspace_size += (sort_index_shape.Size() * 2 * sizeof(int32_t) - 1) / sizeof(DType) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my naive understanding. But, I do not understand why +1? And this mean, we will have one extra size in the workspace always?

Copy link
Member Author

@arcadiaphy arcadiaphy Dec 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will have extra size sometimes when we need to hold int32_t data in DType workspace, and the calculation assures that only the smallest needed space is allocated.

if workspace = (N * sizeof(int32_t) - 1) / sizeof(DType) + 1,
then workspace * sizeof(DType) >= N * sizeof(int32_t) - 1 - (sizeof(DType) - 1) + sizeof(DType)
                                = N * sizeof(int32_t)

Actually, L426 has already calculated correctly.

@sandeep-krishnamurthy sandeep-krishnamurthy added Backend Issues related to the backend of MXNet pr-awaiting-response PR is reviewed and waiting for contributor to respond labels Dec 26, 2018
@wkcn
Copy link
Member

wkcn commented Dec 27, 2018

Is it better to create two workspaces for DType and int32_t respectively?

@zhreshold
Copy link
Member

workspace allocation is limited to one time only, so total space has to be calculated aforehead

@wkcn
Copy link
Member

wkcn commented Dec 27, 2018

@zhreshold Thanks!
I found there is the definition Tensor<xpu, 1, char>.

@Roshrini
Copy link
Member

Roshrini commented Jan 8, 2019

@zhreshold Is this PR good to go?

@zhreshold zhreshold merged commit 5784363 into apache:master Jan 8, 2019
rondogency pushed a commit to rondogency/incubator-mxnet that referenced this pull request Jan 9, 2019
@arcadiaphy arcadiaphy deleted the fix_ssd branch February 15, 2019 07:49
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Backend Issues related to the backend of MXNet pr-awaiting-response PR is reviewed and waiting for contributor to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in `python': malloc(): memory corruption: 0x00007f540c0a6190
5 participants